#include "block_queue.hpp"
#include "Task.hpp"
#include <pthread.h>
#include <unistd.h>

void* Consumer(void* arg)
{
    block_queue<task_t> *bq = static_cast<block_queue<task_t>*>(arg);
     while(true) 
    {
    //1. 获取数据
    task_t t;
    bq->Pop(&t); 
    //2. 处理数据
   
        //sleep(1);
        t();
    }
}

void* Productor(void* arg)
{
    block_queue<task_t> *bq = static_cast<block_queue<task_t>*>(arg);
    while(true)
    {
        sleep(2);
        bq->push(DownLoad);
        std::cout<<"Productor -> Downloda"<<std::endl;
    }
}

int main()
{
    block_queue<task_t> *bq = new block_queue<task_t>();

    pthread_t c,p;

    pthread_create(&c,nullptr,Consumer,bq);
    pthread_create(&p,nullptr,Productor,bq);


    pthread_join(c,nullptr);
    pthread_join(p,nullptr);


    return 0;
}